package cn.tedu.egmvc2.controller;

import ch.qos.logback.core.joran.util.beans.BeanUtil;
import cn.tedu.egmvc2.mapper.AddressMapper;
import cn.tedu.egmvc2.pojo.dto.AddressInsertDTO;
import cn.tedu.egmvc2.pojo.entity.Address;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("address/")
public class AddressController {
    @Autowired
    AddressMapper addressMapper;
    @RequestMapping("insert")
    public String insert(AddressInsertDTO addressInsertDTO)
    {
        Address address = new Address();
        BeanUtils.copyProperties(addressInsertDTO,address);

       addressMapper.insertAddress(address);

        return "添加成功";
    }
    @RequestMapping("select")
    public List<Address> select(){
        return addressMapper.select();
    }
    @RequestMapping("delete")
    public String delete(int id){
        addressMapper.deleteAddressById(id);
        return "删除成功";
    }
    @RequestMapping("update")
    public String update(Address address){
        addressMapper.updateAddressById(address);
        return  "修改成功";
    }
}
